package com.itheima.controller;

import com.itheima.common.R;
import com.itheima.pojo.backend.Category;
import com.itheima.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/category")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;


    @PostMapping
    public R add(HttpServletRequest request,@RequestBody Category category) {
        return categoryService.add(request,category);
    }

    /**
     * 分页查询
     */
    @GetMapping("/page")
    public R select(Integer page,Integer pageSize,String name){
        return categoryService.select(page,pageSize,name);
    }

    @GetMapping("/list")
    public R list(){
        return categoryService.list();
    }


    /**
     * 删除
     * @param id
     * @return
     */
    @DeleteMapping
    public R delete(String id) {
        return categoryService.delete(id);
    }

    @PutMapping
    public R updatCategory(HttpServletRequest request, @RequestBody Category category){
        return categoryService.updatCategory(request, category);
    }


}
